<!DOCTYPE html>

<head>
    <meta charset="UTF-8">
    <title>CSS 文字覆盖图像悬停效果 – 淡入透明</title>
    <style>
        .container {
            position: relative;
            width: 50%;
        }

        .image {
            opacity: 1;
            display: block;
            width: 100%;
            height: auto;
            transition: .5s ease;
            backface-visibility: hidden;
        }

        .middle {
            transition: .5s ease;
            opacity: 0;
            position: absolute;
            top: 50%;
            left: 50%;
            transform: translate(-50%, -50%);
            -ms-transform: translate(-50%, -50%)
        }

        .container:hover .image {
            opacity: 0.3;
        }

        .container:hover .middle {
            opacity: 1;
        }

        .text {
            background-color: #4CAF50;
            color: white;
            font-size: 16px;
            padding: 16px 32px;
        }
    </style>
</head>

<body>
    <h2>淡入透明效果</h2>
    <p>鼠标移动到图片上查看效果</p>

    <div class="container">
        <img src="https://static.runoob.com/images/mix/img_avatar.png" alt="Avatar" class="image">
        <div class="overlay">
            <div class="text">Hello World</div>
        </div>
    </div>
</body>

</html>